package com.imti.mall.product.controller;

import com.github.pagehelper.PageHelper;
import com.imti.mall.common.Api.CommonPage;
import com.imti.mall.common.Api.CommonResult;
import com.imti.mall.model.pms.pojo.PmsSkuStock;
import com.imti.mall.model.pms.vo.PmsProductParam;
import com.imti.mall.product.service.PmsProductServiceS;
import com.imti.mall.product.service.PmsSkuStockService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/v1/product")
public class PmsProductControllerS {

    @Resource
    private PmsProductServiceS pmsProductService;
    @Resource
    private PmsSkuStockService pmsSkuStockService;

    @RequestMapping("/findproduct")
    public CommonResult fetchList(PmsProductParam pmsProductParam){
        PageHelper.startPage(pmsProductParam.getPageNum(),pmsProductParam.getPageSize());
        return CommonResult.success(CommonPage.restPage(pmsProductService.fetchList(pmsProductParam)));
    }

    @PostMapping("/updatePmsProductPublishStatusById")
    public CommonResult updatePublishStatus(@RequestParam(value = "ids") List<Integer> ids, Integer publishStatus){
            return  CommonResult.success(pmsProductService.updatePublishStatus(ids,publishStatus));

    }

    @PostMapping("/updatePmsProductNewStatusById")
    public CommonResult updateNewStatus(@RequestParam(value = "ids") List<Integer> ids,Integer newStatus){
        return  CommonResult.success(pmsProductService.updateNewStatus(ids,newStatus));

    }

    @PostMapping("/updatePmsProductRecommandStatusById")
    public CommonResult updateRecommendStatus(@RequestParam(value = "ids") List<Integer> ids,Integer recommandStatus){
        return  CommonResult.success(pmsProductService.updateRecommendStatus(ids,recommandStatus));

    }

    @RequestMapping ("/delproduct")
    public  CommonResult updateDeleteStatus(@RequestParam(value = "id") List<Integer> ids, Integer deleteStatus){
        return CommonResult.success(pmsProductService.updateDeleteStatus(ids,deleteStatus));
    }

    @GetMapping("/getproduct/{id}")
    public  CommonResult getProduct(@PathVariable("id") Integer id){
        return  CommonResult.success(pmsProductService.getProduct(id));

    }

    @GetMapping("/getPmsSkuStockproductProductSkuCode/{pid}")
    public  CommonResult fetchListSku(@PathVariable("pid")Integer pid){
       // return CommonResult.success();
        return CommonResult.success(pmsSkuStockService.fetchListSku(pid));
    }

    @PostMapping("/updateSkuStockById")
    public CommonResult updateSkuStockById(@RequestBody List<PmsSkuStock> pmsSkuStocks){
        return CommonResult.success(pmsSkuStockService.updateSkuStockById(pmsSkuStocks)) ;
    }

}
